package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author houChen
 * @date 2022/2/2 21:42
 * @Description:  订单确认页需要的数据
 */
public class OrderConfirmVo {

    //收货地址
    @Getter @Setter
    List<MemberAddressVo> address;

    //购物车中所有选中的购物项
    @Getter @Setter
    List<OrderItemVo> items;

    @Getter @Setter
    Map<Long, Boolean> stocks;

    //发票

    //优惠券  会员积分
    @Getter @Setter
    Integer integration;

    //防止重复提交令牌
    @Getter @Setter
    String orderToken;

    //订单中所有商品的总数量
    public Integer getCount(){
        Integer sum = 0;
        if(items!=null){
            for (OrderItemVo item : items) {
                sum = sum + item.getCount();
            }
        }
        return sum;
    }


    //BigDecimal total;//订单总额

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal(0);
        if(items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

   // BigDecimal payPrice; //应付价格
    public BigDecimal getPayPrice() {
        return getTotal();
    }
}